package com.bigdatan.b2c.conf;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.slsy.weixin.mp.api.WxMpInMemoryConfigStorage;
import com.slsy.weixin.mp.api.WxMpMessageRouter;
import com.slsy.weixin.mp.api.WxMpServiceImpl;

@Configuration
@EnableAutoConfiguration
public class WXMpConfig {
	
	@Autowired
	private WXYMLConfig wxConfig;
	
	@Bean
    public WxMpInMemoryConfigStorage wxMpConfigStorage() {
		WxMpInMemoryConfigStorage wxmp = new WxMpInMemoryConfigStorage();
		wxmp.setAppId(wxConfig.getAPPID());
		wxmp.setSecret(wxConfig.getSECRET());
		wxmp.setToken(wxConfig.getTOKEN());
		wxmp.setAesKey(wxConfig.getAESKEY());
		return wxmp;
	}
	
	@Bean
    public WxMpServiceImpl wxMpServiceImpl() {
		WxMpServiceImpl wxs = new WxMpServiceImpl();
		wxs.setWxMpConfigStorage(wxMpConfigStorage());
		return wxs;
	}
	@Bean
    public WxMpMessageRouter wxMpMessageRouter() {
		WxMpMessageRouter wxme = new WxMpMessageRouter();
		wxme.setWxMpService(wxMpServiceImpl());
		return wxme;
	}
	
}
